<?php

declare(strict_types=1);

namespace App\Model;


/**
 * @property int $id
 * @property int $uid
 * @property string $device_token ios
 * @property string $version_code 版本号
 * @property int $status 0: ios app前台运行   1：ios app后台运行或者已杀死
 * @property int $ctime 创建时间
 * @property int $update_time 修改时间
 * @property string $package
 * @property int $from 来源
 * @property string $um_token 友盟token
 */
class UserToken extends Model
{
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'tb_user_token';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = [];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'uid' => 'integer', 'status' => 'integer', 'ctime' => 'integer', 'update_time' => 'integer', 'from' => 'integer'];

    public function uidList2TokenList($uid_list)
    {
        // $sql = sprintf("SELECT uid,um_token FROM {$this->table} WHERE uid IN (%s) AND um_token <> '' AND `status` = ?", $uid_list);
        // $model = $this->conn->prepare($sql);
        // $model->execute([1]);
        // $rs = $model->fetchAll(PDO::FETCH_ASSOC);
        $rs = self::query()->whereIn('uid', $uid_list)->where('status', 1)->where('um_token', '!=', '')
            ->get(['uid', 'um_token'])->toArray();
        return array_column($rs, 'um_token');
    }
}
